import cityData from "./citys.json";

// 城市检索的首字母
var searchLetter = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'W', 'X', 'Y', 'Z'];

let tmpCityObjs = [];
cityData.filter(
        data => tmpCityObjs = tmpCityObjs.concat(data.citys)
 );
const cityObjs = tmpCityObjs;

// 按首字母对城市信息进行分组
function cityList() {
  let tempArr = [];

  searchLetter.map(
    initial => {
      let tempObj = {};
      // let cityInfo = [];
      tempObj.initial = initial;
      tempObj.cityInfo = cityData.filter(
        data => data.initial === initial
      )[0].citys;

      tempArr.push(tempObj);
    }
  );

  // console.log(JSON.stringify(tempArr));
  return tempArr;
}

// function pushCity() {

// }

module.exports = {
  searchLetter: searchLetter,
  cityList: cityList,
  cityObjs: cityObjs
};
